package com.chen.array;

public class ArrayTest {
    public static void main(String[] args) {
        // 目标，完成斗地主游戏的做牌和洗牌
        strat();
    }
    public static void strat() {
        // 1.做牌：创建一个数组，保存45张牌
        String[] pokers = new String[54];
        // pokers = [null, null, null, ....]

        // 准备四种花色，和点数，再开始做牌存入数组中。
        String[] colors = {"♠", "♥", "♣", "♦"};

        String[] numbers = {"3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A", "2"};

        // 3.遍历点数，遍历花色
        int index = 0; // 定义一个变量记录牌存储的索引位置。
        for (int i = 0; i < numbers.length; i++) {
            // 当前点数：numbers[i]
            for (int j = 0; j < colors.length; j++) {
                // 当前花色：colors[j]
                // 4.将牌保存到数组中

                pokers[index++] = colors[j] + numbers[i];

            }

        }

        // 5.将大小王保存到数组中
        pokers[index++] = "🃏";
        pokers[index] = "🃏";

        // 5.打印牌
        System.out.println("新牌：");
        for (int i = 0; i < pokers.length; i++) {
            System.out.print(pokers[i] + "\t");
        }
        System.out.println();

        // 6.洗牌：把54张牌的数组pokers，进行随机排序
        for (int i = 0; i < pokers.length; i++) {
            int index1 = (int)(Math.random() * pokers.length);
            int index2 = (int)(Math.random() * pokers.length);
            String temp = pokers[index1];
            pokers[index1] = pokers[index2];
            pokers[index2] = temp;

            }
        System.out.println("洗牌后：");
        for (int j = 0; j < pokers.length; j++) {
            System.out.print(pokers[j] + "\t");

        }

    }
}
